package cc.plumgo.ss.ui.page;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.GameCanvas;

import cc.plumgo.j2me.utils.CustomPage;
import cc.plumgo.ss.core.Console;
import cc.plumgo.ss.core.Constants;

public class PassPage extends CustomPage {
	public static final int PASS_HIDE = 0;
	public static final int PASS_SHOW = 1;
	public static final int PASS_STATE_NUM = 2;

	private Image image;
	private int height;

	public PassPage() {
		super();
		height = 0;
	}

	public void process(int keyStates, Graphics g) {
		switch (state) {
		case PASS_HIDE: {
			setState(PassPage.PASS_SHOW);
			Console.getInstance().getGameListener().nextLevel();
			break;
		}
		case PASS_SHOW: {
			loadImage();
			g.setColor(0xFFFFFFFF);
			g.fillRect(0, 0, scrWidth, scrHeight);
			g.drawImage(Console.getInstance().getScreen(), 0, 0, 0);
			g.drawImage(image, 46, height, 0);
			if (height < Constants.UI_PASS_HEIGHT) {
				height += 10;
			}

			if ((keyStates & GameCanvas.FIRE_PRESSED) != 0) {
				setState(PASS_HIDE);
			}
			break;
		}
		}
	}

	public void loadImage() {
		if (image == null) {
			try {
				image = Image.createImage(Constants.UI_IMG_PASS);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}
